﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace CommandModel{
	// "Invoker" 
	public class Invoker 
	{ 
		// Fields 
		private Command command; 

		// Methods 
		public void SetCommand( Command command ) 
		{ 
			this.command = command; 
		} 

		public void ExecuteCommand() 
		{ 
			command.Execute(); 
		} 
	} 

	public class User{
		Calculator calculator = new Calculator();
		List<Command> commands = new List<Command>();
		int current = 0;
		public void Redo(int levels = 1){
			Debug.Log (" ---- redo " + levels + "levels");
			for (int i = 0; i < levels; i++) {
				if (current < commands.Count - 1) {
					((Command)commands [current++]).Execute ();
				}
			}
		}
		public void UnDo(int leaves = 1){
			for (int i = 0; i < leaves; i++) {
				if (current > 0) {
					((Command)commands [--current]).UnExecute ();
				}
			}
		}

		public void Compute(char @operator,int operand){
			Command cammand = new CalculatorCommand (calculator, @operator, operand);
			cammand.Execute ();

			commands.Add (cammand);
			current++;
			Debug.Log ("current"+current);
		}
	}
}